package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/setmeal")
@Api(tags="套餐管理")
@Slf4j
public class SetmealController {

    private final SetmealService setmealService;

    public SetmealController(SetmealService setmealService) {
        this.setmealService = setmealService;
    }

    @PostMapping("/add")
    @ApiOperation("添加套餐")
    public Result add(@RequestBody SetmealDTO setmealDTO){
        log.info("添加套餐: {}", setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @PutMapping
    @ApiOperation("修改套餐")
    public Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("修改套餐: {}", setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }

    @PutMapping("/status/{status}")
    @ApiOperation("起售停售")
    public Result startOrStop(Integer id,@PathVariable("status") Integer status) {
        log.info("起售停售: {},id {}", status, id);
        setmealService.startOrStop(status,id);
        return Result.success();
    }

    @GetMapping("/delete")
    @ApiOperation("删除套餐")
    public Result delete(Long id){
        log.info("删除套餐: {}", id);
        setmealService.delete(id);
        return Result.success();
    }

}
